package cn.ll.po;

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

/**
 * A data access object (DAO) providing persistence and search support for
 * Cuscontact entities. Transaction control of the save(), update() and delete()
 * operations can directly support Spring container-managed transactions or they
 * can be augmented to handle user-managed Spring transactions. Each of these
 * methods provides additional information for how to configure it for the
 * desired type of transaction control.
 * 
 * @see cn.ll.po.Cuscontact
 * @author MyEclipse Persistence Tools
 */

public class CuscontactDAO extends HibernateDaoSupport {
	private static final Log log = LogFactory.getLog(CuscontactDAO.class);
	// property constants
	public static final String NAME = "name";
	public static final String CUSTOMERID = "customerid";
	public static final String CUSTOMERNAME = "customername";
	public static final String DUTY = "duty";
	public static final String EMAIL = "email";
	public static final String PHONE = "phone";
	public static final String MOBILE = "mobile";
	public static final String AGE = "age";
	public static final String GENDER = "gender";
	public static final String PERSONALITY = "personality";
	public static final String REMARK = "remark";

	protected void initDao() {
		// do nothing
	}

	public void save(Cuscontact transientInstance) {
		log.debug("saving Cuscontact instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(Cuscontact persistentInstance) {
		log.debug("deleting Cuscontact instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public Cuscontact findById(java.lang.Integer id) {
		log.debug("getting Cuscontact instance with id: " + id);
		try {
			Cuscontact instance = (Cuscontact) getHibernateTemplate().get(
					"cn.ll.po.Cuscontact", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List<Cuscontact> findByExample(Cuscontact instance) {
		log.debug("finding Cuscontact instance by example");
		try {
			List<Cuscontact> results = (List<Cuscontact>) getHibernateTemplate()
					.findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding Cuscontact instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from Cuscontact as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List<Cuscontact> findByName(Object name) {
		return findByProperty(NAME, name);
	}

	public List<Cuscontact> findByCustomerid(Object customerid) {
		return findByProperty(CUSTOMERID, customerid);
	}

	public List<Cuscontact> findByCustomername(Object customername) {
		return findByProperty(CUSTOMERNAME, customername);
	}

	public List<Cuscontact> findByDuty(Object duty) {
		return findByProperty(DUTY, duty);
	}

	public List<Cuscontact> findByEmail(Object email) {
		return findByProperty(EMAIL, email);
	}

	public List<Cuscontact> findByPhone(Object phone) {
		return findByProperty(PHONE, phone);
	}

	public List<Cuscontact> findByMobile(Object mobile) {
		return findByProperty(MOBILE, mobile);
	}

	public List<Cuscontact> findByAge(Object age) {
		return findByProperty(AGE, age);
	}

	public List<Cuscontact> findByGender(Object gender) {
		return findByProperty(GENDER, gender);
	}

	public List<Cuscontact> findByPersonality(Object personality) {
		return findByProperty(PERSONALITY, personality);
	}

	public List<Cuscontact> findByRemark(Object remark) {
		return findByProperty(REMARK, remark);
	}

	public List findAll() {
		log.debug("finding all Cuscontact instances");
		try {
			String queryString = "from Cuscontact";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public Cuscontact merge(Cuscontact detachedInstance) {
		log.debug("merging Cuscontact instance");
		try {
			Cuscontact result = (Cuscontact) getHibernateTemplate().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(Cuscontact instance) {
		log.debug("attaching dirty Cuscontact instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(Cuscontact instance) {
		log.debug("attaching clean Cuscontact instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static CuscontactDAO getFromApplicationContext(ApplicationContext ctx) {
		return (CuscontactDAO) ctx.getBean("CuscontactDAO");
	}
}